package com.roamer.school.repository.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * 事务管理配置
 *
 * @author roamer
 * @version V1.0
 * @date 2-02-20 22:07
 */
@EnableTransactionManagement
@Configuration
public class TransactionConfig {

    /**
     * 如果只有一个事务管理器，则无需配置
     *
     * @param dataSource 数据源
     *
     * @return {@code PlatformTransactionManager} JDBC/MyBatis所使用的事务管理器
     */
    @Bean(name = "txManager")
    public PlatformTransactionManager txManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
}
